package com.yuanduo_app.adapter;

import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class FragmentViewPagerAdapter extends FragmentPagerAdapter {
    private FragmentManager fragmetnmanager;  //创建FragmentManager
    private List<Fragment> listfragment; //创建一个List<Fragment>
    private List<String> mTitleList;

    //定义构造带两个参数
    public FragmentViewPagerAdapter (FragmentManager fm, List<Fragment> list) {
        super(fm);
        this.fragmetnmanager = fm;
        this.listfragment = list;
    }

    public FragmentViewPagerAdapter (FragmentManager fm, List<Fragment> listfragment, List<String> titleList) {
        super(fm);
        this.fragmetnmanager = fm;
        this.listfragment = listfragment;
        mTitleList = titleList;
    }

    @Override
    public Fragment getItem (int arg0) {
        // TODO Auto-generated method stub
        return listfragment.get(arg0); //返回第几个fragment
    }

    @Override
    public int getCount () {
        // TODO Auto-generated method stub
        return listfragment.size(); //总共有多少个fragment
    }

    @Nullable
    @Override
    public CharSequence getPageTitle (int position) {
        return mTitleList == null ? super.getPageTitle(position) : mTitleList.get(position);
    }
}
